<?php
class AccessModel extends Model {
	public function getAccessTree(){
		$cateList = $this->getAll();
		
		$newCateList = array();
		foreach($cateList as $key=>$val){
			if($val['pid'] == 0){
				$newCateList[] = $cateList[$key];
				unset($cateList[$key]);
			}	
		}
		
		foreach($newCateList as $k=>$v){
			$newCateList[$k]['tree'] = $this->getAccessSonTree($cateList, $v['id']);	
		}
		return $newCateList;
	}
	public function getAccessSonTree($cateList, $code){
		  $newCateList = array();
		  foreach($cateList as $key=>$val){
			  if($val['pid'] == $code){
				  $newCateList[$key] = $cateList[$key];
				  unset($cateList[$key]);
				  $newCateList[$key]['tree'] = $this->getAccessSonTree($cateList, $val['id']);	
			  }	
		  }
		  
		  return $newCateList;
	}
}